import { useLocation, useNavigate } from "react-router-dom";
export default function useRouterIntercept() {
  const location = useLocation();
  const navigate = useNavigate();
  function handleVerify() {
    if (!localStorage.getItem("token") && location.pathname !== "/login") {
      navigate("/login");
    }
    let user: any = localStorage.getItem("user");
    user && (user = JSON.parse(user!));
    if (user?.rid >= 3 && location.pathname.includes("/user")) {
      navigate(-1);
    }
  }
  return [handleVerify];
}
